import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-06-29
 * Time: 23:35
 */
//https://leetcode.cn/problems/implement-queue-using-stacks/submissions/640051591/
    //用两个栈实线队列
class MyQueue {
    Stack p1;
    Stack p2;
    public MyQueue() {
        p1=new Stack();
        p2=new Stack();

    }

    public void push(int x) {
        p1.push(x);
    }

    public int pop() {
        if(p2.isEmpty()){
            while(!p1.isEmpty()){
                p2.push(p1.pop());
            }
        }
        return (int)p2.pop();
    }

    public int peek() {
        if(p2.isEmpty()){
            while(!p1.isEmpty()){
                p2.push(p1.pop());
            }
        }
        return (int)p2.peek();
    }

    public boolean empty() {
        if(p1.isEmpty()&&p2.isEmpty()){
            return true;
        }
        else{
            return false;
        }
    }
}
public class Test {
    public static void main(String[] args) {
        MyQueue queue=new MyQueue();
        queue.push(1);
        queue.push(2);
        queue.push(3);
        System.out.println(queue.peek());
        queue.pop();
        queue.pop();
        System.out.println(queue.peek());
        queue.pop();
        System.out.println(queue.empty());
    }

}
